var http = require('http');

// The url we want is `10.0.10.67:5984/scorecard`
var options = {
  host : '10.111.0.100',
  path : '/scorecard',
  port : '5984',
  method : 'POST',
  headers : {
    'Content-Type' : 'application/json'
  }

};

callback = function(response) {
  var str = '';
  response.on('data', function(chunk) {
    str += chunk;
  });

  response.on('end', function() {
    console.log(str);
  });
};

var dayForMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var vote = new Array(1, 3, 5);

// all months
for ( var month = 0; month < 12; month++) {
  // all days
  for ( var day = 1; day <= dayForMonth[month]; day++) {
    // 15 votes at day
    for ( var voteForDay = 0; voteForDay < Math.round(Math.random() * 40); voteForDay++) {
      var date = new Date();
      date.setFullYear(2012, month, day);
      date.setHours(Math.round(Math.random() * 9 + 8), Math
        .round(Math.random() * 59), Math.round(Math.random() * 59), Math
        .round(Math.random() * 59));
      var sendVote = vote[Math.round(Math.random() * 2)];

      // only working days
      if (date.getDay() > 0 && date.getDay() < 6) {
        var obj = {
          'date' : date.toString(),
          'vote' : sendVote
        };
        // send vote
        var req = http.request(options, callback);
        req.write(JSON.stringify(obj));
        req.end();
      }

    }

  }
}
